# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=mautrix-whatsapp
pkgver=0.10.5
pkgrel=1
pkgdesc="Matrix-WhatsApp puppeting bridge"
url="https://maunium.net/go/mautrix-whatsapp"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/whatsapp/archive/v$pkgver.tar.gz
	mautrix-whatsapp.initd
	mautrix-whatsapp.confd
	default-log-dir.patch
	"
builddir="$srcdir/whatsapp-$pkgver"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	go build
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-whatsapp \
		-t "$pkgdir"/usr/bin/
	install -Dm644 example-config.yaml \
		-t "$pkgdir"/etc/mautrix-whatsapp/

	install -Dm755 "$srcdir"/mautrix-whatsapp.initd \
		"$pkgdir"/etc/init.d/mautrix-whatsapp
	install -Dm644 "$srcdir"/mautrix-whatsapp.confd \
		"$pkgdir"/etc/conf.d/mautrix-whatsapp
}

sha512sums="
2642c015619db5eb77bc79224ee95b90041367adeba79a0f88a757f48bad07975220ff4b1efbe5107c846e93512f4d710ad0a4f9ce3230a2103121c2f0277712  mautrix-whatsapp-0.10.5.tar.gz
428253b07200b66c8ac364d9238665b7e93de1797f0f49b4a9b2513445613e7b0f06716b1c91f883c51a1e9115a2cf8f716364e61fea0a416faa78cfb86783aa  mautrix-whatsapp.initd
9349b660273c63d2973f1b99ddbd98469dddc098157380603210159f17d3cb1eb55e71dbd21550b20d40831f4da320225e7c03441667e2750e30a2e1fa03acfe  mautrix-whatsapp.confd
d5b66b40dde25f24986788669b91dfafe2f35f901b87ff30bfe8c8ab663ebbbe9bd10ac974f73115abd935eb0f27d5645fcbe641a6c6925c24eaa8c7fa9ab6b7  default-log-dir.patch
"
